import 'package:flutter/material.dart';
import 'package:lai_zhan/common/style/AppStyle.dart';

//单选框
class RowRadio extends StatefulWidget {
  List<String> radioNames;
  ValueChanged<String> onChange;
  String select;
  RowRadio({this.radioNames, this.onChange,this.select});

  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    select = radioNames[0];
    return new _RowRadioState(radioNames, onChange,select);
  }
}

class _RowRadioState extends State<RowRadio> {
  List<String> radioNames;
  ValueChanged<String> onChange;
  String _select;

  _RowRadioState(this.radioNames, this.onChange,this._select);

  _renderItem() {
    var radios = radioNames
        .map((str) => new Row(
              mainAxisSize: MainAxisSize.min,
              children: <Widget>[
                new Text(str),
                new Radio(
                    activeColor: Color(AppColors.primaryColor),
                    value: str,
                    groupValue: _select,
                    onChanged: (str) {
                      this._select = str;
                      print(str);
                      onChange(_select);
                    })
              ],
            ))
        .toList();
    return new Row(
      children: radios,
      mainAxisSize: MainAxisSize.max,
      mainAxisAlignment: MainAxisAlignment.center,
    );
  }

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return new Container(
      padding: EdgeInsets.all(5),
      child: _renderItem(),
    );
  }
}
